﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Collections.Generic
{
    public static class EnumerableExtensions
    {

        public static IEnumerable<T> PagedItems<T>(this IEnumerable<T> allItems, int pageSize, int currentPage, out int totalPages) where T : class
        {
            int len = allItems.Count();

            if ((len % pageSize) == 0)
            {
                totalPages = len / pageSize;
            }
            else
            {
                totalPages = len / pageSize + 1;
            }

            IEnumerable<T> items = allItems.Skip(pageSize * currentPage);
            items = items.Take(pageSize);

            return items;
        }

    }
}
